<html>
<head><meta charset="utf-8"><title>object safety phrasing · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html">object safety phrasing</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="164338599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164338599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164338599">(Apr 27 2019 at 14:38)</a>:</h4>
<p>Is it accurate to say that the fundamental reason that a given trait cannot be made into an object is because it's not possible to construct / select the vtable at that point in time?</p>



<a name="164338635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164338635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164338635">(Apr 27 2019 at 14:40)</a>:</h4>
<p>There's also the unsized aspect, which I know is being worked on via unsized rvalues, so I'm ignoring that when i state "fundamental"</p>



<a name="164340712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340712">(Apr 27 2019 at 15:31)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  ^--- would "type erasure safe"  have been a better phrasing?</p>



<a name="164340719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340719">(Apr 27 2019 at 15:31)</a>:</h4>
<p>hmpf</p>



<a name="164340720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340720">(Apr 27 2019 at 15:31)</a>:</h4>
<p>not exactly</p>



<a name="164340722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340722">(Apr 27 2019 at 15:31)</a>:</h4>
<p>(explaining why e.g. <code>for&lt;T&gt; fn(T)</code> and <code>dyn for&lt;T&gt; Fn(T)</code> ain't OK)</p>



<a name="164340765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340765">(Apr 27 2019 at 15:32)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> so if we're only taking the "no generic methods" problem</p>



<a name="164340769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340769">(Apr 27 2019 at 15:32)</a>:</h4>
<p>it's the possibility of reification of the vtable <em>at all</em></p>



<a name="164340778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340778">(Apr 27 2019 at 15:33)</a>:</h4>
<p>with non-generic functions, you have a finite number of <code>fn</code> pointers, and that's enough</p>



<a name="164340787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340787">(Apr 27 2019 at 15:33)</a>:</h4>
<p>to do dynamic dispatch</p>



<a name="164340791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340791">(Apr 27 2019 at 15:33)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> eh, I think that assumes too much</p>



<a name="164340794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340794">(Apr 27 2019 at 15:33)</a>:</h4>
<p>(deleted)</p>



<a name="164340797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340797">(Apr 27 2019 at 15:33)</a>:</h4>
<p>sorry, Zulip is annoying, UI-wise</p>



<a name="164340842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340842">(Apr 27 2019 at 15:34)</a>:</h4>
<p>(deleted)</p>



<a name="164340862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340862">(Apr 27 2019 at 15:35)</a>:</h4>
<p>You can by clicking a <code>v</code> that is visible on the left I tihnk, but only within 10 minutes of writing the message. Or maybe not.</p>



<a name="164340869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340869">(Apr 27 2019 at 15:35)</a>:</h4>
<p>doesn't seem so</p>



<a name="164340915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340915">(Apr 27 2019 at 15:36)</a>:</h4>
<p>it's on the right</p>



<a name="164340917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340917">(Apr 27 2019 at 15:36)</a>:</h4>
<blockquote>
<p>with non-generic functions, you have a finite number of fn pointers, and that's enough</p>
</blockquote>
<p>(Treating lifetime generic functions as non-generic due to parametricity)</p>



<a name="164340985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164340985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164340985">(Apr 27 2019 at 15:39)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <em>is</em> it correct that there's only the two categories feeding into object safety today: generics and unsized? Make sure I'm not missing an avenue</p>



<a name="164341057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164341057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164341057">(Apr 27 2019 at 15:40)</a>:</h4>
<p>The second is being able to implement <code>Trait</code> for <code>dyn Trait</code> (which implies the stuff around <code>Sized</code> if you treat <code>std::mem::swap</code> as an honorary method of <code>Sized</code>).</p>



<a name="164341115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164341115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164341115">(Apr 27 2019 at 15:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> I'm not seeing the connection with <code>swap</code>  here... could you expand a smidge?</p>



<a name="164341203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164341203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164341203">(Apr 27 2019 at 15:45)</a>:</h4>
<p>The signature of <code>swap</code> is (effectively) <code>fn swap(&amp;mut self, other: &amp;mut Self)</code>, which isn't object safe because the second parameter references <code>Self</code>.</p>



<a name="164341273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164341273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164341273">(Apr 27 2019 at 15:47)</a>:</h4>
<p>And such signatures aren't object safe because there's no way to "glue together" all of the individual implementations into one for <code>dyn Sized</code></p>



<a name="164341319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164341319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164341319">(Apr 27 2019 at 15:48)</a>:</h4>
<p>No matter how we implemented trait objects</p>



<a name="164343059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343059">(Apr 27 2019 at 16:34)</a>:</h4>
<p>uhhhhhhhh</p>



<a name="164343064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343064">(Apr 27 2019 at 16:34)</a>:</h4>
<p>a <code>swap</code> method is perfectly fine</p>



<a name="164343068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343068">(Apr 27 2019 at 16:34)</a>:</h4>
<p>we're just not implementing <code>dyn Trait</code> fully today</p>



<a name="164343074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343074">(Apr 27 2019 at 16:34)</a>:</h4>
<p>you could use it, in the future, for something like <code>&amp;mut [dyn Trait]</code></p>



<a name="164343075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343075">(Apr 27 2019 at 16:35)</a>:</h4>
<p>since that's <code>&amp;mut [T]</code> for an unknown <code>T</code></p>



<a name="164343090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343090">(Apr 27 2019 at 16:35)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> okay fine I mean "only erasable generics". which is I guess what  your point was</p>



<a name="164343094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343094">(Apr 27 2019 at 16:36)</a>:</h4>
<p>What would swap even do with two different types?</p>



<a name="164343095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343095">(Apr 27 2019 at 16:36)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> yep</p>



<a name="164343141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343141">(Apr 27 2019 at 16:36)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> it would require same-type</p>



<a name="164343149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343149">(Apr 27 2019 at 16:36)</a>:</h4>
<p>which... is a thing you can statically typecheck and lots of  formalisms have had for  like... half a century even?</p>



<a name="164343151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343151">(Apr 27 2019 at 16:36)</a>:</h4>
<p>we should consider <code>dyn for&lt;T: ?Concrete&gt; Fn(T)</code> or something</p>



<a name="164343154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343154">(Apr 27 2019 at 16:36)</a>:</h4>
<p>what</p>



<a name="164343172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343172">(Apr 27 2019 at 16:37)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> ?</p>



<a name="164343222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343222">(Apr 27 2019 at 16:38)</a>:</h4>
<p>anyway, like I said, <code>[dyn Trait]</code>, by the only rules that are known to work, must come from a <code>[T; n]</code> where <code>T: Sized</code> and <code>n: usize</code></p>



<a name="164343224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343224">(Apr 27 2019 at 16:38)</a>:</h4>
<p>the element type can't vary between elements</p>



<a name="164343231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343231">(Apr 27 2019 at 16:38)</a>:</h4>
<p>that would mean that you'd end up with the same skolem variable when accessing elements</p>



<a name="164343245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343245">(Apr 27 2019 at 16:39)</a>:</h4>
<p>so e.g. a <code>[ref mut a, ref mut b, ..]</code> pattern would know that <code>a</code> and <code>b</code> are <em>not only</em> <code>dyn Trait</code>, but <em>the same concrete type</em></p>



<a name="164343246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343246">(Apr 27 2019 at 16:39)</a>:</h4>
<p>and so you could swap them!</p>



<a name="164343248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343248">(Apr 27 2019 at 16:39)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> same story for <code>Vec&lt;dyn Trait&gt;</code> presumably?</p>



<a name="164343249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343249">(Apr 27 2019 at 16:39)</a>:</h4>
<p>yupp</p>



<a name="164343255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343255">(Apr 27 2019 at 16:39)</a>:</h4>
<p>that's just a growable <code>Box&lt;[dyn Trait]&gt;</code></p>



<a name="164343309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343309">(Apr 27 2019 at 16:40)</a>:</h4>
<p><span aria-label="ship" class="emoji emoji-1f6a2" role="img" title="ship">:ship:</span></p>



<a name="164343310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343310">(Apr 27 2019 at 16:40)</a>:</h4>
<p>(not swap them with <code>mem::swap</code>, that'd be harder, but with a <code>swap</code> method)</p>



<a name="164343316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343316">(Apr 27 2019 at 16:40)</a>:</h4>
<p>Zulip makes it tedious to correct typos, lol</p>



<a name="164343319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343319">(Apr 27 2019 at 16:40)</a>:</h4>
<p>/me checks what the equivalent of <code>Vec&lt;dyn Trait&gt;</code> is in Haskell</p>



<a name="164343336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343336">(Apr 27 2019 at 16:41)</a>:</h4>
<p>it probably involves the keyword <code>forall</code> because gotta love Haskell</p>



<a name="164343338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343338">(Apr 27 2019 at 16:41)</a>:</h4>
<p>yup</p>



<a name="164343340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343340">(Apr 27 2019 at 16:41)</a>:</h4>
<p>but, basically, you just put the binder outside the <code>[]</code></p>



<a name="164343388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343388">(Apr 27 2019 at 16:42)</a>:</h4>
<p>if you put it inside, that's like <code>Vec&lt;Box&lt;dyn Trait&gt;&gt;</code></p>



<a name="164343397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343397">(Apr 27 2019 at 16:42)</a>:</h4>
<p>Rust has implicit binder slots in <code>*const</code>, <code>*mut</code>, <code>&amp;</code> and <code>&amp;mut</code> <em>and nothing else</em></p>



<a name="164343412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343412">(Apr 27 2019 at 16:43)</a>:</h4>
<p>I keep meaning to write this up instead of ranting about it once it a while</p>



<a name="164343413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343413">(Apr 27 2019 at 16:43)</a>:</h4>
<p>it fits together pretty well</p>



<a name="164343416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343416">(Apr 27 2019 at 16:43)</a>:</h4>
<p>please do</p>



<a name="164343554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343554">(Apr 27 2019 at 16:46)</a>:</h4>
<div class="codehilite"><pre><span></span>&lt;interactive&gt;:11:5: error:
    * My brain just exploded
      I can&#39;t handle pattern bindings for existential or GADT data constructors.
      Instead, use a case-expression, or do-notation, to unpack the constructor.
</pre></div>



<a name="164343706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343706">(Apr 27 2019 at 16:51)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> </p>
<div class="codehilite"><pre><span></span><span class="cm">{-# LANGUAGE ExistentialQuantification, RankNTypes, ConstraintKinds, KindSignatures #-}</span>

<span class="kr">import</span> <span class="nn">Data.Kind</span>

<span class="kr">data</span> <span class="kt">DynList</span> <span class="p">(</span><span class="n">c</span> <span class="ow">::</span> <span class="o">*</span> <span class="ow">-&gt;</span> <span class="kt">Constraint</span><span class="p">)</span> <span class="ow">=</span> <span class="n">forall</span> <span class="p">(</span><span class="n">t</span> <span class="ow">::</span> <span class="o">*</span><span class="p">)</span><span class="o">.</span> <span class="n">c</span> <span class="n">t</span> <span class="ow">=&gt;</span> <span class="kt">DL</span> <span class="p">[</span><span class="n">t</span><span class="p">]</span>

<span class="nf">main</span> <span class="ow">=</span> <span class="n">print</span> <span class="o">$</span> <span class="kr">case</span> <span class="kt">DL</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">]</span> <span class="ow">::</span> <span class="kt">DynList</span> <span class="kt">Show</span> <span class="kr">of</span> <span class="kt">DL</span> <span class="n">xs</span> <span class="ow">-&gt;</span> <span class="n">show</span> <span class="o">&lt;$&gt;</span> <span class="n">xs</span>
</pre></div>



<a name="164343838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343838">(Apr 27 2019 at 16:54)</a>:</h4>
<p><a href="https://github.com/goldfirere/singletons/pull/228" target="_blank" title="https://github.com/goldfirere/singletons/pull/228">https://github.com/goldfirere/singletons/pull/228</a> <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span></p>



<a name="164343848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/object%20safety%20phrasing/near/164343848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/object.20safety.20phrasing.html#164343848">(Apr 27 2019 at 16:55)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> seems perfectly reasonable to me</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>